// pages/operation/classRecord/classJoin/index.js
import {
  ClassModel
} from "../../../../api/api-work/classModel.js";
const classModel = new ClassModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    total: 0,
    tableDatas: [],
    loadStatus: "",
    triggered: false,
    courseId: "",
    studentId: "",
    studentName: "",
    orderNo: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    const param = JSON.parse(options.param);
    this.setData({
      courseId: param.courseId,
      studentId: param.studentId,
      orderNo: param.orderNo,
      studentName: param.studentName
    })
    await this.getClassList()

  },

  // 班级列表
  async getClassList() {
    classModel.getClassListApi({
      pageNum: this.data.pageNum,
      pageSize: 15,
      beOver: 1,
      courseId: this.data.courseId
    }).then(res => {
      let rows = this.data.tableDatas;
      rows.push(...res.rows);
      this.setData({
        tableDatas: rows,
        total: res.total
      })
      if (this.data.total == 0) {
        this.setData({
          loadStatus: ""
        })
      } else if (this.data.tableDatas.length < this.data.total) {
        this.setData({
          loadStatus: "loadmore"
        })
      } else {
        this.setData({
          loadStatus: "nomore"
        })
      }
    })
  },
  getMoreClass() {
    if (this.data.loadStatus === "nomore") {
      return;
    }
    this.setData({
      pageNum: this.data.pageNum + 1,
      loadStatus: "loading"
    })
    this.getClassList();
  },
  refreshMoreClass() {
    this.setData({
      triggered: false,
      pageNum: 1,
      tableDatas: []
    })
    this.getClassList();
  },
  // 去选择课次
  toClassMakeUpTimes(e) {
    console.log('去选择课次++++++++',e.currentTarget);
    const param = JSON.stringify({
      studentId: this.data.studentId,
      orderNo: this.data.orderNo,
      studentName: this.data.studentName,
      classId: e.currentTarget.dataset.query.id,
      className: e.currentTarget.dataset.query.name,
    })
    wx.navigateTo({
      url: `/pages/operation/classRecord/classMakeUpTimes/index?param=${param}`,
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})